﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bll;
using Help;
using Model;

namespace Myproject.BSM.Ashx.PcBase
{
    /// <summary>
    /// ContactEdit 的摘要说明
    /// </summary>
    public class ContactEdit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Params["pc_base_ContactEdit_ContactID"].Trim();
            string name = context.Request.Params["pc_base_ContactEdit_name"].Trim();
            string ename = context.Request.Params["pc_base_ContactEdit_ename"].Trim();
            string post = context.Request.Params["pc_base_ContactEdit_post"].Trim();
            string epost = context.Request.Params["pc_base_ContactEdit_epost"].Trim();
            string phone = context.Request.Params["pc_base_ContactEdit_phone"].Trim();
            string tel = context.Request.Params["pc_base_ContactEdit_tel"].Trim();
            string email = context.Request.Params["pc_base_ContactEdit_email"].Trim();
            string rank = context.Request.Params["pc_base_ContactEdit_rank"].Trim();
            string show = context.Request.Params["pc_base_ContactEdit_show"].Trim();
            if (id == "0")
            {
                ContactModel model = new ContactModel();
                model.Name = name;
                model.EName = ename;
                model.Post = post;
                model.EPost = epost;
                model.MobilePhone = phone;
                model.OfficePhone = tel;
                model.Email = email;
                model.Rank = int.Parse(rank);
                model.Show = bool.Parse(show);

                if (new ContactBLL().Add(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "新增联系方式成功！", "pc_base_contactList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "新增联系方式失败！", "pc_base_contactList", "", "", true, "", ""));
                }
            }
            else
            {
                ContactModel model = new ContactBLL().GetModel(Int32.Parse(id));
                model.Name = name;
                model.EName = ename;
                model.Post = post;
                model.EPost = epost;
                model.MobilePhone = phone;
                model.OfficePhone = tel;
                model.Email = email;
                model.Rank = int.Parse(rank);
                model.Show = bool.Parse(show);
                if (new ContactBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改联系方式成功！", "pc_base_contactList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改联系方式失败！", "pc_base_contactList", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}